<template>
  <!-- 排行榜左边导航 -->
  <div class="left_nav">
    <div
      class="item"
      v-for="(item,index) in topList"
      :key="item.id"
      :class="currentTopList == item.name ? 'active' : ''"
      @click="choiceRankingList(item,index)"
    >
      <div class="pic">
        <img v-lazy="item.coverImgUrl" alt="" class="pic_url" />
      </div>
      <div class="explain">
        <div class="name">
          {{ item.name }}
        </div>
        <div class="update_frequency">{{ item.updateFrequency }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, inject, ref, watch } from "vue";
export default defineComponent({
  name: "LeftNav",
  setup(props, context) {
    let topList = inject("topList");
    let currentTopList = ref("");

    // 初始化默认榜单是第一个
    watch(topList, () => {
      currentTopList.value = topList.value[0].name;
    });

    // 点击排行榜回调
    let choiceRankingList = (item,index) => {
      if (currentTopList.value == item.name) {
        return;
      }
      item.index = index
      currentTopList.value = item.name;
      context.emit("choiceRankingList", item);
    };

    return {
      topList,
      currentTopList,
      choiceRankingList,
    };
  },
});
</script>
<style scoped>
.left_nav {
  width: 25%;
  border-right: 1px solid #eee;
}
.item {
  width: 100%;
  display: flex;
  align-items: center;
  margin: 20px 0;
  padding-left: 40px;
  cursor: pointer;
}
.item:hover {
  box-shadow: 0px 0px 10px -1px #222;
}
.active {
  box-shadow: 0px 0px 10px -1px #222;
}
.pic {
  width: 80px;
  height: 80px;
  margin-right: 10px;
}
.pic_url {
  width: 100%;
  height: 100%;
  border-radius: 2px;
}
.name {
  font-weight: 600;
  color: #222;
  font-size: 18px;
  margin-bottom: 10px;
}
.update_frequency {
  font-size: 16px;
  color: #888;
}
</style>
